package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ParkingRecordIn;
import com.ruoyi.service.IParkingRecordInService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆进场记录Controller
 * 
 * @author dongdong
 * @date 2025-08-23
 */
@RestController
@RequestMapping("/parking/recordIn")
public class ParkingRecordInController extends BaseController
{
    @Autowired
    private IParkingRecordInService parkingRecordInService;

    /**
     * 查询车辆进场记录列表
     */
    @PreAuthorize("@ss.hasPermi('parking:recordIn:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkingRecordIn parkingRecordIn)
    {
        startPage();
        List<ParkingRecordIn> list = parkingRecordInService.selectParkingRecordInList(parkingRecordIn);
        return getDataTable(list);
    }

    /**
     * 导出车辆进场记录列表
     */
    @PreAuthorize("@ss.hasPermi('parking:recordIn:export')")
    @Log(title = "车辆进场记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkingRecordIn parkingRecordIn)
    {
        List<ParkingRecordIn> list = parkingRecordInService.selectParkingRecordInList(parkingRecordIn);
        ExcelUtil<ParkingRecordIn> util = new ExcelUtil<ParkingRecordIn>(ParkingRecordIn.class);
        util.exportExcel(response, list, "车辆进场记录数据");
    }

    /**
     * 获取车辆进场记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:recordIn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(parkingRecordInService.selectParkingRecordInById(id));
    }

    /**
     * 新增车辆进场记录
     */
    @PreAuthorize("@ss.hasPermi('parking:recordIn:add')")
    @Log(title = "车辆进场记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkingRecordIn parkingRecordIn)
    {
        return toAjax(parkingRecordInService.insertParkingRecordIn(parkingRecordIn));
    }

    /**
     * 修改车辆进场记录
     */
    @PreAuthorize("@ss.hasPermi('parking:recordIn:edit')")
    @Log(title = "车辆进场记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkingRecordIn parkingRecordIn)
    {
        return toAjax(parkingRecordInService.updateParkingRecordIn(parkingRecordIn));
    }

    /**
     * 删除车辆进场记录
     */
    @PreAuthorize("@ss.hasPermi('parking:recordIn:remove')")
    @Log(title = "车辆进场记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(parkingRecordInService.deleteParkingRecordInByIds(ids));
    }

    /**
     * 远程开闸 - 通过入场记录id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('parking:recordIn:edit')")
    @Log(title = "远程开闸", businessType = BusinessType.DELETE)
    @GetMapping("/openGateById/{id}")
    public AjaxResult openGateById(@PathVariable("id") String id){
        return success(parkingRecordInService.openGateById(id));
    }

    /**
     * 远程开闸 - 通过订单的订单编号
     * @param serialNumber 下级平台的交易流水号，云平台的订单号
     * @return
     */
    @PreAuthorize("@ss.hasPermi('parking:recordIn:edit')")
    @Log(title = "远程开闸", businessType = BusinessType.DELETE)
    @GetMapping("/openGateBySerialNumber/{serialNumber}")
    public AjaxResult openGateBySerialNumber(@PathVariable("serialNumber") String serialNumber){
        return success(parkingRecordInService.openGateBySerialNumber(serialNumber));
    }
}
